package com.qf.java2107.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.java2107.mapper.PassengerMapper;
import com.qf.java2107.mapper.PassportsMapper;
import com.qf.java2107.pojo.Passenger;
import com.qf.java2107.pojo.Passports;
import com.qf.java2107.service.PassportsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author YB
 * @date 2022/01/08
 * @VERSION V1.0
 **/
@Service
@Transactional
public class PassportsServiceImpl implements PassportsService {

    @Autowired
    private PassengerMapper passengerMapper;

    @Autowired
    private PassportsMapper passportsMapper;


    @Override
    public List<Passports> findAll() {
        return passportsMapper.selectByExample(null);
    }

    @Override
    public PageInfo<Passports> findPage(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        //查询护照
        List<Passports> passports = passportsMapper.selectByExample(null);

        for (Passports passport : passports) {
            Passenger passenger = passengerMapper.selectByPrimaryKey(passport.getPassengerId());
            passport.setPassenger(passenger);
        }
        return new PageInfo<>(passports);

    }

    @Override
    public Passports findById(Integer id) {
        return passportsMapper.selectByPrimaryKey(id);
    }

    @Override
    public int update(Passports passports) {
        return passportsMapper.updateByPrimaryKeySelective(passports);
    }

    @Override
    public void delete(Integer id) {
        passportsMapper.deleteByPrimaryKey(id);
    }

}
